import {inject, observer} from 'mobx-react';
import {toJS} from 'mobx';
import { Select, Input, Button, Modal } from 'antd'
import {WeaDialog, WeaLocaleProvider, WeaRightMenu } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import * as blogUtil from '../../../../util/index';

@inject('blogMyBlog')
@observer
export default class CreateGroupModal extends React.Component {
    constructor(props) {
        super(props)
        this.state = {}
    }
    getRightMenu = () => {
        let btns = [
            {
                key: 'CREATE_SAVE',
                icon: <i className='icon-coms-Preservation' />,
                content: getLabel(30986, "保存"),
                onClick: () => this.onRightMenuClick('BTN_SAVE')
            }
        ];
        return btns;
    }

    onRightMenuClick = (type) => {
        const { blogMyBlog } = this.props;
        const { groupDialogForm,moduleStatus } = blogMyBlog;
        const formParams = groupDialogForm && groupDialogForm.getFormParams();
        if (type == 'BTN_SAVE') {
            blogUtil.onCheck(groupDialogForm, () => {
                let params = {...formParams};
                if(moduleStatus.createOrEdit == 'edit'){
                    params = {...formParams, groupId: moduleStatus.editKey};
                }
                this.props.requestData(params);
                blogMyBlog.groupDialogForm.resetForm();
            })
        }
    }

    render() {
        const {blogMyBlog} = this.props;
        const {showGroupCreate, groupDialogFields,createOrEdit} = toJS(blogMyBlog.moduleStatus);

        let title = getLabel(30131, "新建分组");

        if(createOrEdit=='edit'){
            title = getLabel(83149, "编辑分组");
        }else if(createOrEdit=='createAndMove'){
            title = getLabel(31194, "新建分组并移动");
        }else if(createOrEdit=='createAndCopy'){
            title = getLabel(31195, "新建分组并复制");
        }
        
        
        const collectParams={
          favname: title,
          favouritetype: 1,
          objid:0,
          link:'wui/engine.html#/blogengine/setting',
          importantlevel: 1,
        };
    
        return (
          <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@w00w33`}
            title={title}
            icon="icon-coms-blog"
            iconBgcolor="#6d3cf7"
            style={{width: 600, height: 90}}
            visible={showGroupCreate}
            buttons={[
              <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@r3zgnr@${createOrEdit}`} key="submit" type="primary" onClick={() => this.onRightMenuClick('BTN_SAVE')}>{getLabel(30986, "保存")}</Button>
            ]}
            moreBtn={{collectParams: collectParams}}
            onCancel={() => {
                blogMyBlog.setModuleState({showGroupCreate: false});
                blogMyBlog.groupDialogForm.resetForm();
            }}
          >
            <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@3b6fgj`}
              datas={this.getRightMenu()}
              collectParams={{collectParams}}
            >
              {blogUtil.getFormSearchs(blogMyBlog.groupDialogForm, groupDialogFields,false,false,false,this.props.ecId || '')}
            </WeaRightMenu>
          </WeaDialog>
        )
      }
}